﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ASCalpuff.FileLayers
{
    public class MG7 : Group
    {

        private List<SS> m_SS = new List<SS>();

        //地面站点参数
        //1：  站点名字为四位字符       (MUST START IN COLUMN 9)
        //2： 站点编号为5位数字

        # region 属性
        public List<SS> SS
        {
            get { return m_SS; }

            //去掉对应的设置器，小付
            // set { m_SS = value; }
        }


        # endregion


        # region  方法

        public override string WriteToGroup()
        {
            string ResultStr = "", TempStr;
            string END = "\r\n";

            TempStr = "INPUT GROUP: 7 -- Surface meteorological station parameters" + END;
            ResultStr += TempStr;

            TempStr = "SURFACE STATION VARIABLES" + END;
            ResultStr += TempStr;


            TempStr = "        Name   ID            X coord.   Y coord.   Time   Anem" + END;
            ResultStr += TempStr;

            int i = 1;
            foreach (SS myss in this.SS)
            {
                string A = new string(myss.CSNAM);
                TempStr = "! SS" + i.ToString() + "  ='" + A + "'    " + myss.IDSSTA.ToString() + "       " + Math.Round(myss.XSSTA, 3).ToString()
                    + "     " + Math.Round(myss.YSSTA, 3).ToString() + "   " + myss.XSTZ.ToString() + "    " + Math.Round(myss.ZANEM, 2).ToString() + "  !" + END;

                ResultStr += TempStr;

                i++;

            }

            TempStr = "! END !" + END;
            ResultStr += TempStr;

            TempStr = StrWriter.GetCLine();
            ResultStr += TempStr;

            return ResultStr;


            //return "";
        }


        # endregion

        public override void ReadFromGroup(Dictionary<string, string> dic)
        {
            //int p = -1;
            SS s = new SS();

            foreach (KeyValuePair<string, string> m_dic in dic)
            {
                //p += 1;
                //if (m_dic.Key == "SS" +p)
                //{

                //}
                this.SS.Add(s.ReadFromGroup(m_dic.Value));
            }
        }




    }


    public class SS
    {

        //4字符站名，必须包含在单引号中，如'STA1','STA2'
        //前引号必须位于每个记录的第9（或大于9列）
        char[] m_CSNAM = new char[4];

        public char[] CSNAM
        {
            get { return m_CSNAM; }
            set { m_CSNAM = value; }
        }

        //站点编码，六位有效数字
        int m_IDSSTA;

        public int IDSSTA
        {
            get { return m_IDSSTA; }
            set { m_IDSSTA = value; }
        }

        //地面站点的X,Y坐标
        double m_XSSTA;

        public double XSSTA
        {
            get { return m_XSSTA; }
            set { m_XSSTA = value; }
        }
        double m_YSSTA;

        public double YSSTA
        {
            get { return m_YSSTA; }
            set { m_YSSTA = value; }
        }

        //站点所在时区（05东部标准时间，06中部标准时间，07山地标准时间，08太平洋标准时间）
        double m_XSTZ;

        public double XSTZ
        {
            get { return m_XSTZ; }
            set { m_XSTZ = value; }
        }

        //风速计有效高度
        double m_ZANEM;

        public double ZANEM
        {
            get { return m_ZANEM; }
            set { m_ZANEM = value; }
        }
        public SS ReadFromGroup(string str)
        {
            SS s = new SS();

            this.CSNAM = StrWriter.GetString(str, 1).ToCharArray();
            this.IDSSTA = Convert.ToInt32(StrWriter.GetString(str, 2));
            this.XSSTA = Convert.ToDouble(StrWriter.GetString(str, 3));
            this.YSSTA = Convert.ToDouble(StrWriter.GetString(str, 4));
            this.XSTZ = Convert.ToDouble(StrWriter.GetString(str, 5));
            this.ZANEM = Convert.ToDouble(StrWriter.GetString(str, 6));
            return s;
        }

    }

}
